package com.selfdriving.wl.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.selfdriving.BaseFragmentActivity;
import com.selfdriving.R;

public class ChatFragment extends BaseFragmentActivity implements
		OnClickListener
{
	private MyFriendsFragment mPeopleFragment;
	private MyGrpupsFragment myGrpupsFragment;
	private Button myFriends;
	private Button myGroups;
	private Button add;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.w_activity_chat);
		initViews();
		initEvents();
	}

	@Override
	protected void initViews()
	{
		// TODO Auto-generated method stub
		mPeopleFragment = new MyFriendsFragment(mApplication, this, this);
		myGrpupsFragment = new MyGrpupsFragment(mApplication, this, this);
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		ft.replace(R.id.nearby_layout_content, mPeopleFragment).commit();
		myFriends = (Button) findViewById(R.id.chat_my_friends);
		myGroups = (Button) findViewById(R.id.chat_my_groups);
		add = (Button) findViewById(R.id.chat_add);
		myFriends.setSelected(true);
		myGroups.setSelected(false);
	}

	@Override
	protected void initEvents()
	{
		// TODO Auto-generated method stub
		myFriends.setOnClickListener(this);
		myGroups.setOnClickListener(this);
		add.setOnClickListener(this);
	}

	@Override
	public void onClick(View v)
	{
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		ft.setCustomAnimations(R.anim.fragment_fadein, R.anim.fragment_fadeout);
		switch (v.getId())
		{
		case R.id.chat_my_friends:
			myFriends.setSelected(true);
			myGroups.setSelected(false);
			ft.replace(R.id.nearby_layout_content, mPeopleFragment).commit();
			break;

		case R.id.chat_my_groups:
			myFriends.setSelected(false);
			myGroups.setSelected(true);
			ft.replace(R.id.nearby_layout_content, myGrpupsFragment).commit();
			break;
		case R.id.chat_add:
			startActivity(AddMyFriendsManage.class);
			break;
		}
	}

}
